app.controller('commonController',function ($scope){

//分页控件配置,itemsPerPage 每页记录数 perPageOptions 每页记录数可选项 onChange 页码发生改变时触发这个函数
    $scope.paginationConf = {
        currentPage: 1,
        totalItems: 10,
        itemsPerPage: 10,
        perPageOptions: [10, 20, 30, 40, 50],
        //刚进入本页面，页面从没有变为 1，onChange 也发生了改变
        onChange: function () {
            $scope.reloadList();
        }
    };

//重新加载列表
    $scope.reloadList = function () {
        $scope.search($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);

    }

//选中的要删除的
    $scope.selected = [];
    $scope.updateSelected = function ($event, id) {
        if ($event.target.checked) {
            $scope.selected.push(id);
        } else {
            var idx = $scope.selected.indexOf(id);
            $scope.selected.splice(idx, 1);
        }
    }

    //把字符串转换成 json 类型
    $scope.JsonFromString=function (string ,key) {
        var json=JSON.parse(string);
        var value ="";
        //i<json.length 不能<=
        for(var i=0;i < json.length;i++){
            if (i>0){
                value+=",";
            }
            value+=json[i][key];
        }
        return value;
    }
});